import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;

/**
 * 描述：快速修改 系统 hosts文件；<BR/>
 * 
 * @author mch
 *
 */
public class Hosts {

	public static void main(String[] args) throws Exception {
		String parm = args[0];
		File hosts = new File("C:/Windows/System32/drivers/etc/hosts");

		if ("#".equals(parm)) {
			String filepath = "hosts#.txt";
			FileReader fr = new FileReader(filepath);
			BufferedReader br = new BufferedReader(fr);
			char[] chartmps = new char[512];
			int count = br.read(chartmps);

			FileWriter fw = new FileWriter(hosts);
			BufferedWriter bw = new BufferedWriter(fw);
			while (count > 0) {
				bw.write(chartmps, 0, count);
				count = br.read(chartmps);
			}
			br.close();
			fr.close();

			bw.flush();
			fw.close();
		} else {
			String filepath = "hosts-.txt";
			FileReader fr = new FileReader(filepath);
			BufferedReader br = new BufferedReader(fr);
			char[] chartmps = new char[512];
			int count = br.read(chartmps);

			FileWriter fw = new FileWriter(hosts);
			BufferedWriter bw = new BufferedWriter(fw);
			while (count > 0) {
				bw.write(chartmps, 0, count);
				count = br.read(chartmps);
			}
			br.close();
			fr.close();

			bw.flush();
			fw.close();
		}
	}

}
